const socketUrl = 'ws://192.168.1.5:8360/ws';

let socketObj = null, socketOpen =false;
export const initSocket = () => {
	if(socketObj) return socketObj;
	 socketObj = uni.connectSocket({
		url: socketUrl,
		header: {
			'content-type': 'application/json',
			'x-zyt-token': uni.getStorageSync('token')
		},
		success:function(){
			console.log('21312132')
		}
	});
	socketObj.onOpen(() =>{
		console.log('WebSocket opened');
		socketOpen = true;
	});
	socketObj.onMessage((message) =>{
		const data = JSON.parse(message.data);
		console.log('Received message from server:', data);
	});
	socketObj.onClose(() =>{
		console.log('WebSocket closed');
		socketOpen = false;
	});
	socketObj.onError((error) =>{
		console.error('WebSocket error:', error);
	});
	return socketObj;
}
// export const getScoket = ()=> socketObj;
export const getsocketOpen = ()=> socketOpen;
// export const socketOpen = ()=>{
// 	return socketOpen;
// }
